#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int q[N];
int n;
int len = 1;
int find(int x)
{
	
	int l = 0;
	int r = len + 1;
	while(l + 1 < r){
		int mid = (l + r) >> 1;
		if (q[mid] < x) l = mid;
		else r = mid;
	}
	return r;
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	q[1] = arr[1];
	for (int i = 2; i <= n; i++) {
		if (arr[i] > q[len]) {
			q[++len] = arr[i];
		}
		else {
			int idx = find(arr[i]);
			q[idx] = arr[i];
		}
	}
	cout << len << endl;
	return 0;
}